<template>
  <transition name="fade" @after-leave="afterLeave" @after-enter="afterEnter">
    <div class="notification-page" :style='style' v-show='visible' @mouseenter='clearTimer' @mouseleave="createTimer">
      <span class="handle-close">{{notification}}</span>
      <a type="btn" class="btn" @click='handleClose'>{{btn}}</a>
    </div>
  </transition>
</template>

<script>
export default {
  name: 'Notification',
  props: {
    notification: {
      type: String,
      required: true
    },
    btn: {
      type: String,
      default: 'close'
    }
  },
  computed: {
    style () {
      return {}
    }
  },
  methods: {
    handleClose (e) {
      e.preventDefault()
      this.$emit('close')
    },
    afterLeave () {
      this.$emit('closed')
    },
    afterEnter () {},
    clearTimer () {},
    createTimer () {}
  },
  data () {
    return {
      visible: true
    }
  }
}
</script>

<style scoped lang='scss'>
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.5s;
}
.fade-enter,
.fade-leave-to {
  opacity: 0;
}
.notification-page {
  display: flex;
  background-color: #303030;
  color: rgba(225, 225, 225, 1);
  align-items: center;
  padding: 20px;
  position: fixed;
  min-width: 280px;
  box-shadow: 0 3px 5px -1px rgba(0, 0, 0, 0.2);
  flex-wrap: wrap;
  transform: all 0.3s;
  & > .handle-close {
    padding: 0;
  }
  & > .btn {
    color: #ff4081;
    padding-left: 24px;
    margin-left: auto;
    cursor: pointer;
  }
}
</style>
